//
//  HJDefaultCenterView.m
//  12期传智微博HJ
//
//  Created by mac on 15-2-3.
//  Copyright (c) 2015年 jun. All rights reserved.
//

#import "HJDefaultCenterView.h"
@interface HJDefaultCenterView()

/**
 *  图标
 */

@property (weak, nonatomic) IBOutlet UIImageView *icon;
/**
 *  描述
 */
@property (weak, nonatomic) IBOutlet UILabel *descriptionLB;
/**
 *  登陆按钮
 */
@property (weak, nonatomic) IBOutlet UIButton *loginBtn;

/**
 *  注册按钮
 */
@property (weak, nonatomic) IBOutlet UIButton *registerBtn;
/**
 *  定时器
 */
@property (nonatomic, strong) CADisplayLink *link;
/**
 *  点击登录
 *
 *  @param sender <#sender description#>
 */
- (IBAction)loginBtnClick:(UIButton *)sender;
/**
 *  点击注册
 */
- (IBAction)registerBtnOnClick:(UIButton *)sender;

@end

@implementation HJDefaultCenterView

+ (instancetype)defaultCenterView
{
    return [[[NSBundle mainBundle] loadNibNamed:@"HJDefaultCenterView" owner:nil options:nil] lastObject];
}

- (void)setIconImageName:(NSString *)iconImageName
{
    self.icon.image = [UIImage imageNamed:iconImageName];
}

- (void)setInfo:(NSString *)info
{
    self.descriptionLB.text = info;
}
- (void)update
{
    self.turntableIv.transform = CGAffineTransformRotate(self.turntableIv.transform, M_PI / 100);
}
/**
 *  开始转动
 *
 *  @param sender <#sender description#>
 */
- (void)startRotate
{
    //创建定时器
    //将定时器添加到事件循环
    [self.link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
}
- (void)stopRotate
{
    //销毁定时器
    [self.link invalidate];
    self.link = nil;
}

/**
 *  登录
 *
 *  @param sender <#sender description#>
 */

- (IBAction)loginBtnClick:(UIButton *)sender {
    if ([self.delegate respondsToSelector:@selector(defaultCenterView:didClickLogin:)]) {
        [self.delegate defaultCenterView:self didClickLogin:sender];
    }
}
- (IBAction)registerBtnOnClick:(UIButton *)sender {
    if ([self.delegate respondsToSelector:@selector(defaultCenterView:didClickRegister:)]) {
        [self.delegate defaultCenterView:self didClickRegister:sender];
    }
}
#pragma mark - 懒加载
- (CADisplayLink *)link
{
    if (!_link) {
        _link = [CADisplayLink displayLinkWithTarget:self selector:@selector(update)];
    }
    return _link;
}
@end
